package mini_game_fx;

import java.awt.image.BufferedImage;
import java.util.HashMap;
import javafx.scene.image.Image;
import javafx.scene.image.ImageView;
/**
 * A SpriteType describes a particular type of Sprite. In most games,
 * artwork is shared between similar game objects. So, if a game has
 * 20 Orcs, they all share the same artwork. We don't want to load
 * images for each Orc, that's a waste of resources. Instead, we load
 * the art once, and share it. This is common practice in all types of
 * applications.
 * 
 * @author Richard McKenna
 * @version 1.0
 */
public class SpriteTypeFx implements Cloneable
{
	// EACH SpriteType HAS A UNIQUE NAME FOR IDENTIFYING IT,
	// SHOULD THE NEED ARISE.
	private String spriteTypeID;
	
	// A SpriteType MAY HAVE A NUMBER OF DIFFERENT IMAGES TO REPRESENT
	// IT. FOR EXAMPLE, A CHARACTER SPRITE MAY HAVE ONE FOR FACING LEFT,
	// RIGHT, UP, AND DOWN, SO EACH WOULD BE CONSIDERED A DIFFERENT
	// STATE, AND SO EACH IMAGE SHOULD BE PLACED HERE, MAPPING A UNIQUE
	// STATE NAME TO AN IMAGE.
	private HashMap<String, MiniGameImageView> states;
	private HashMap<MiniGameImageView, String> images;
	
	// WIDTH AND HEIGHT OF THIS SpriteType's IMAGES
	private int width;
	private int height;
	
	public SpriteTypeFx(String initSpriteTypeID)
	{
		spriteTypeID = initSpriteTypeID;
		states = new HashMap<String, MiniGameImageView>();
		images = new HashMap<MiniGameImageView, String>();
		width = -1;
		height = -1;
	}
	
	// ACCESSOR METHODS
		// getSpriteTypeID
		// getStateImage
		// getHeight
		// getWidth
	
	/**
	 * Accesses and returns the ID (name) of this
	 * sprite type.
	 * 
	 * @return this SpriteType's unique ID
	 */
	public String getSpriteTypeID() { return spriteTypeID; }

	/**
	 * Accessor method for accessing and returning the Image
	 * that correponds to a given state.
	 * 
	 * @param stateName the state for which one wishes to
	 * access the image.
	 * 
	 * @return the image registered for the stateName state.
	 */
	public MiniGameImageView getStateImage(String stateName)
	{
		return states.get(stateName);
	}
        
	public String getImageState(MiniGameImageView bf)
	{
		return images.get(bf);
	}
	
	/**
	 * Accesses and returns the height of all the images used
	 * by this SpriteType. Note that all images for a given
	 * SpriteType should be identically sized.
	 * 
	 * @return the height in pixels of this SpriteType
	 */
	public int getHeight() { return height; }

	/**
	 * Accesses and returns the width of all the images used
	 * by this SpriteType. Note that all images for a given
	 * SpriteType should be identically sized.
	 * 
	 * @return the width in pixels of this SpriteType
	 */
	public int getWidth() { return width; }

	/**
	 * Adds a state, along with its corresponding image, to
	 * this SpriteType object.
	 * 
	 * @param stateName the state to use in registering the image.
	 * 
	 * @param img the Image to use for rendering when a given
	 * SpriteType is set with stateName as its state
	 */
	public void addState(String stateName, MiniGameImageView img)
	{
		if (states.isEmpty())
		{
			width = (int)img.getImage().getWidth();
			height = (int)img.getImage().getHeight();
		}
		states.put(stateName, img);
		images.put(img, stateName);
	}
        
        public SpriteTypeFx clone(){
            System.out.println("spritetypeFx clone method");
            SpriteTypeFx temp = new SpriteTypeFx(this.getSpriteTypeID());
//            temp.sets
            
            temp.setStates((new HashMap<String, MiniGameImageView>()));//states.clone());
            temp.setImages((new HashMap<MiniGameImageView, String>()));//)images.clone());
            
            for(HashMap.Entry<String, MiniGameImageView> entry : this.states.entrySet()) {
               temp.addState(entry.getKey(), ((MiniGameImageView)entry.getValue()).clone());
            }
//            temp.setStates((HashMap<String, MiniGameImageView>)states.clone());
//            temp.setImages((HashMap<MiniGameImageView, String>)images.clone());
            
            temp.setWidth(this.getWidth());
            temp.setHeight(this.getHeight());
            
            return temp;
        }
    
    private void setStates(HashMap<String, MiniGameImageView> states) {
        this.states = states;
    }

    private void setImages(HashMap<MiniGameImageView, String> images) {
        this.images = images;
    }

    private void setWidth(int width) {
        this.width = width;
    }

    private void setHeight(int height) {
        this.height = height;
    }
        
        
}